'use strict';

module.exports = (req, res, rfun)=>{
    if(!(req.SESSION.userid > 0)){
        res.setHeader("location","/Login/Index?resultUrl="+req.GET.pathname);
        res.statusCode = 302;
        res.end('{s:1,m:"error",u:"/Login/Index?resultUrl='+req.GET.pathname+'"}');
        rfun(false);
        return;
    }
    if(req.GET.pathname == "/Home/Index"){
        req.PUBFUN.DBM.executeSql("SELECT UserID,Score,InsureScore FROM QPTreasureDB.dbo.GameScoreInfo where UserID=" + req.SESSION.userid,(row)=>{
            if(row.UserID){
                req.SESSION.score = row.Score[0];
                req.SESSION.insurescore = row.InsureScore[0];
            }
            rfun(req.SESSION);
        })
    }else{
        rfun(req.SESSION);
    }
}